package com.ejd.service.impl;


import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.ejd.service.IGoodsService;
import com.ejd.service.IOperateService;
import com.ejd.web.bo.impl.Goods;

public class GoodsService extends OperateServiceImp<Goods, Long> implements IOperateService<Goods,Long>,
		IGoodsService<Goods, Long> {

	public List<String> getPropertyCodes(String property, List<String>params, List<String>values){
		List<String> result = new ArrayList();
		Map criteria = new HashMap();
		String hql="select distinct " + "g." + property +
				" from Goods as g where 1=1";
		if (null != params && null != values) {
			for (int i=0;i < params.size(); i++) {
				hql = hql + " and g." + params.get(i) + " = :" +params.get(i);
				criteria.put(params.get(i), values.get(i));
			}
		}
		SessionFactory sf =(SessionFactory) this.getGenericDao().getHibernateTemplate().getSessionFactory();
		Session session = sf.openSession();
		try {
			Query q = session.createQuery(hql);
			q.setProperties(criteria);
			session.beginTransaction();
			result = q.list();
			session.flush();
			} catch (HibernateException e) {
				e.printStackTrace();
				session.getTransaction().rollback();
			} finally {
				session.close();
			  }
		return result;
	
	}
}
